package com.sgai.zero_robot.pop;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.sgai.zero_robot.R;
import com.sgai.zero_robot.utils.DeviceUtils;


/**
 * Describe :
 * Created by zzw on 2024/3/21
 */
public class AlarmDialog extends BaseDialog{

    private TextView tvTitle;
    private View vLine;
    private ImageView ivAlarm;
    private TextView tvContent;

    public AlarmDialog(Context context) {
        super(context);
    }

    @Override
    public int getDialogHeight() {
        return DeviceUtils.dp2px(getContext(), 180);
    }

    public void setContent(int type,String title,String msg) {
        if (type == 1){
            if (tvTitle!=null){
                tvTitle.setTextColor(Color.parseColor("#FF5959"));
                tvTitle.setText(title);
            }
            if (vLine!=null){
                vLine.setBackgroundColor(Color.parseColor("#FF5959"));
            }
            if (ivAlarm!=null){
                ivAlarm.setImageDrawable(getContext().getResources().getDrawable(R.mipmap.alarm1));
            }
        }else if (type == 2){
            if (tvTitle!=null){
                tvTitle.setTextColor(Color.parseColor("#FF931E"));
                tvTitle.setText(title);
            }
            if (vLine!=null){
                vLine.setBackgroundColor(Color.parseColor("#FF931E"));
            }
            if (ivAlarm!=null){
                ivAlarm.setImageDrawable(getContext().getResources().getDrawable(R.mipmap.alarm2));
            }
        }
        if (tvContent != null) {
            tvContent.setText(msg);
        }
        if (getWindow() != null) {
            getWindow().setBackgroundDrawableResource(R.drawable.shape_dbf4ff_10);
        }
    }
    @Override
    public int getDialogWidth() {
        return DeviceUtils.dp2px(getContext(), 390);
    }

    @Override
    protected void initContentView(View mContentView) {
        if (mContentView != null) {
            tvTitle = mContentView.findViewById(R.id.tv_title);
            vLine = mContentView.findViewById(R.id.v_line);
            ivAlarm = mContentView.findViewById(R.id.iv_alarm);
            tvContent = mContentView.findViewById(R.id.tv_content);
            mContentView.findViewById(R.id.bt_know).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                    if (alarmCallback!=null){
                        alarmCallback.onKnow();
                    }
                }
            });
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.alarm_layout;
    }

    @Override
    public boolean getBackgroundDimEnabled() {
        return true;
    }


    @Override
    public int getGravity() {
        return Gravity.CENTER;
    }
    private AlarmCallback alarmCallback;

    public void setAlarmCallback(AlarmCallback alarmCallback) {
        this.alarmCallback = alarmCallback;
    }

    public interface AlarmCallback{
        void onKnow();
    }
}